package com.springboot.controller;

import com.springboot.domain.Student;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.websocket.server.PathParam;

@RestController
@RequestMapping("/t2c")
public class Test2Controller {

    @RequestMapping("/t1")
    public String t1(){
        return "/view/t1.html";
    }

    @RequestMapping("/t2")
    public Student getStudent(Student stu){
        return stu;
    }

    @RequestMapping("/t3/{id}")
    public String getId(@PathVariable(value = "id") int id){
        return "传入的id="+id;
    }

    @RequestMapping("/t4")
    public String getName(@PathParam(value="name") String name){
        return "传入的名字="+name;
    }

    @RequestMapping("/t5")  //RequestMapping都可以接收Post Get提交的请求
    public String getSex(HttpServletRequest req){
        String sex = req.getParameter("sex");
        return "传入的性别="+sex;
    }

    @GetMapping("/t6")
    public String getAge(@PathParam(value = "age") int age){
        return "传入的年龄:"+age;
    }

    @PostMapping("/t7")
    public Student findStudent(Student stu){
        return stu;
    }

}
